<?php

namespace app\service;

use app\dao\TaskDao;
use think\facade\Log;
use think\exception\BusinessException;

class TaskService
{
    private $taskDao;

    public function __construct()
    {
        $this->taskDao = new TaskDao();
    }

    // 创建任务
    public function createTask($projectId, $title, $description)
    {
        try {
            $task = $this->taskDao->createTask($projectId, $title, $description);
            if (!$task) {
                throw new BusinessException('创建任务失败');
            }
            return $task;
        } catch (\Exception $e) {
            Log::error("创建任务失败: " . $e->getMessage());
            throw new BusinessException('系统异常，请稍后再试');
        }
    }

    // 获取任务详情
    public function getTaskDetails($taskId)
    {
        try {
            $task = $this->taskDao->getTaskById($taskId);
            if (!$task) {
                throw new BusinessException('任务不存在');
            }
            return $task;
        } catch (\Exception $e) {
            Log::error("获取任务详情失败: " . $e->getMessage());
            throw new BusinessException('系统异常，请稍后再试');
        }
    }
}
    